package cn.edu.fjnu.camera;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent; 
import android.widget.ImageView;

public class MoveImageView extends ImageView 
{
	public int x1,y1;
	public MoveImageView(Context context) 
	{
		super(context);
	}

	public MoveImageView(Context context, AttributeSet attrs) 
	{
		super(context, attrs, 0);
	}

	public MoveImageView(Context context, AttributeSet attrs, int defStyle)
	{
		 super(context, attrs, defStyle);
	}

	public void setLocation(int x,int y) 
	{
		if(x<270&&y<170)
		{
			this.setFrame(x-265, y-60, x + this.getWidth()-265, y+this.getHeight()-60);//这个是左上角
			x1=x-265;
			y1=y-60;
		}
		if(x<270&&y>170)
		{
			this.setFrame(x-265, y- this.getHeight(), x + this.getWidth()-265, y);//这个是左下角
			x1=x-265;
			y1=y- this.getHeight();
		}
		if(x>270&&y<170)
		{
			this.setFrame(x-this.getWidth(), y-60, x, y+ this.getHeight()-60);//右上角
			x1=x-this.getWidth();
			y1=y-60;
		}
		if(x>270&&y>170)
		{
			this.setFrame(x-this.getWidth(), y- this.getHeight(), x, y);//右下角
			x1=x-this.getWidth();
			y1=y-this.getHeight();
		}
	}
	
	public boolean autoMouse(MotionEvent event) 
	{
		boolean rb = false;
		switch (event.getAction()) 
		{
			case MotionEvent.ACTION_MOVE:
					this.setLocation((int) event.getX(), (int) event.getY());
					rb = true;
			break;
		}
		return rb;
	}
}
